//合并表格
export function rowspan(data: any[], key:string) {
  //每次调用清空数据
  let spanArr:number[] = [];
  let position = 0;
  //this.dataList存放表格数据数组
  data.forEach((_item, index) => {
    if (index === 0) {
      spanArr.push(1);
      position = 0;
    } else {
      if (
      //serialNo 判断合并列的索引字段
        data[index][key] === data[index - 1][key]
      ) {
        spanArr[position] += 1;
        spanArr.push(0);
      } else {
        spanArr.push(1);
        position = index;
      }
    }
  });
  return spanArr
}
//防抖
export function debounce(fn:Function,delay=200){//fn是需要防抖的函数，delay是延迟多少毫秒执行fn
  let timer:NodeJS.Timeout | null = null;
  return function (){
      if(timer){
          clearTimeout(timer);
      }
      timer=setTimeout(()=>{
          fn.apply(fn,arguments);
          timer = null;
      },delay)
  }
}

// 考试题
function fun(arr) {
  let flag = arr.every(item => typeof item === 'number')
  if(!flag) {
    return '请传入元素都为整数的数组'
  }
  let result = []
  for(let i = 0;i<arr.length-1-2;i++){
    let resultItem = [arr[i]]
    for(let j = i+1;j<arr.length-1-1;j++) {
      resultItem.push(arr[j])
      for(let k = i+2;k<arr.length-1;k++) {
        resultItem.push(arr[k])  
      }
    }
    result.push(resultItem)
  }
  return result
}
fun([-1,0,1,2,-1,-41])